package cn.com.homeyoda.aimate.aihealth.ui.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.ui.my.ActivityBean;

import java.util.List;

public class ActivityListAdapter extends BaseQuickAdapter<ActivityBean, BaseViewHolder> {

    public ActivityListAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ActivityBean item) {
        helper.setText(R.id.tv_title, item.getTitle());
        helper.setText(R.id.tv_desc, item.getDesc());
        helper.setText(R.id.tv_date, "时间：" + item.getTime());
        helper.setText(R.id.tv_user_count, "报名人数：" + item.getUserCount());
        helper.setText(R.id.tv_register, item.getRegisterCount() + "人已报名");
        boolean isJoined = item.getStatus() == 1;
        boolean isFinished = item.getType() == 4;
        helper.setText(R.id.btn_join, isFinished ? "已结束" : isJoined ? "已参与" : "立即参与");
        helper.setEnabled(R.id.btn_join, !isFinished && !isJoined);
        helper.addOnClickListener(R.id.btn_join);
        helper.setVisible(R.id.view_divider, helper.getAdapterPosition() < getItemCount() - 2);
    }

    @Override
    public void setNewData(@Nullable List<ActivityBean> data) {
        super.setNewData(data);
    }
}
